package com.greenet.companytemplate.manager.service;

import com.greenet.companytemplate.base.service.CrudService;
import com.greenet.companytemplate.manager.dao.SecondMenuDao;
import com.greenet.companytemplate.manager.entity.Menu;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2016/4/26.
 */
@Service
public class SecondMenuService extends CrudService<SecondMenuDao,Menu> {

    /**
     * 根据导航栏获取二级菜单
     * @return
     * @throws Exception
     */
    @Transactional(readOnly = false)
    public int insert(Menu menu){
        dao.insert(menu);
        return Integer.parseInt(menu.getId());
    }

    /**
     * 获取所有的二级菜单（根据主菜单id）
     * @param id
     * @return
     * @throws Exception
     */
    @Transactional(readOnly = false)
    public List<Menu> getSubMenu(int id) throws Exception{
        return dao.getSubMenu(id);
    }
    /**
     * 根据用户上传的文件，更新二级菜单url
     * @param menu
     */
    @Transactional(readOnly = false)
    public void updateUrl(Menu menu){
        dao.updateUrl(menu);
    }

    /**
     * 根据菜单名称查询菜单，去重用
     * @param name
     * @return
     */
    public List<Menu> getMenuByName(String name){
        return dao.getMenuByName(name);
    }

}
